<template>
	<view class="container">
		<view class="user-section">
			<view class="vip-card-box" style="background-image: url(/static/images/card_bg.png);background-size: 100% 100%;">
				<view class="text-white text-xxlx text-center padding-top-lg margin-top-lg">{{ userinfo.yuebao}}</view>
				<view class="text-white text-lg text-center padding-top-sm">宝库余额(元)</view>
			</view>
		</view>
		<view class="cu-form-group margin-lr-lg border-b-line padding-0">
			<view class="title">转出金额</view>
		</view>
		<view class="cu-form-group margin-lr-lg border-b-line padding-0">
			<text class="text-price text-xxlx"></text>
			<input class="text-xxlx" data-key="coin" number focus placeholder="0.00" v-model="coin" @input="inputCoin">
		</view>
		<view class="cu-form-group margin-lr-lg padding-0 submit_btn">
			<button :disabled="enableChu" class="cu-btn" type="button" @click="zhuanchu()">确认转出</button>
		</view>
	</view>
</template>

<script>
    export default {
		data() {
			return {
				coin:'',
				minchu: "1",
				maxchu: "1",
				enableChu: !0,
				userinfo:[],
				list:[]
			};
		},
		onLoad: function (option) {
			this.helper.checkLogin();
			this.getData();
		},
		methods: {
			getData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['username='+info.username,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"getUserInfo",
					timestamp:timestamp,
					data:{username:info.username,token:info.token},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					this.userinfo = res.data.data.userinfo;
					this.maxchu = this.userinfo.yuebao;
					setTimeout(() => {
						uni.hideLoading();
					}, 300);
				})
			},
			inputCoin: function(e) {
				this.enableChu = !(parseFloat(e.detail.value) > 0);
			},
			zhuanchu: function(e) {
				if(this.coin == '' || parseFloat(this.coin) <= 0){
					uni.showToast({
						title:"请输入转出金额",
						icon:"none"
					})
					this.enableChu = !1
					return;
				}
				if(parseFloat(this.coin) < this.minchu){
					uni.showToast({
						title:"转出金额不能小于" + this.minchu,
						icon:"none"
					})
					this.enableChu = !1
					return;
				}
				if(parseFloat(this.coin) > this.maxchu){
					uni.showToast({
						title:"转出金额不能大于" + this.maxchu,
						icon:"none"
					})
					this.enableChu = !1
					return;
				}
				this.enableChu = !0;
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['coin='+this.coin,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"doYuebaoChu",
					timestamp:timestamp,
					data:{coin:this.coin,token:info.token},
					header:{sign:sign},
					method:'POST',
				}).then(res=>{
					uni.showModal({
						title: "提示",
						content: '转出成功',
						showCancel:false,
						confirmText: "确认",
						success:function(res){
							if(res.confirm){
								uni.navigateTo({
									url: "/pages/yuebao/index"
								})
							}
						}
					})
				})
				this.coin = "";
			}
		},
	};
</script>

<style lang="scss">
page {
    background-color: #fff;
}
	.vip-card-box {
		height: 260upx;
		border-radius: 16upx;
		overflow: hidden;
		position: relative;
		padding: 0 20upx 24upx;
		margin: 0 20upx 0;
		line-height: 50upx;
		z-index: 10
	}
	input.text-xxlx{
		font-size: 50upx;
	}
</style>
